import React, { useEffect, useRef, useState } from 'react'
import useGetTableData from '@/hooks/useGetTableDataV2'
import SearchForm from '@/components/QsfCustomForm/SearchForm'
import { useForm } from 'antd/es/form/Form'
import PageContainer from '@/components/PageContainer'
import { useIndexColumns } from './TableColumns'
import { PurchaseFabricPageDataVO as ITableData } from './types'
import CustomTable from '@/components/QsfCustomTable'
import { useAppSelector } from '@/store/hooks'
import { searchConfig } from './FormConfig'
import './index.less'
import useCachePage from '@/hooks/useCachePage'
import { getProductClassConfigByType, getSpuOptions } from '@/api/goods'
import {
  batchUpdateReplyDate,
  getFabricOrderPage,
  getUnReplyDateCount,
  misDeliveryToPurchaseSupplier,
  misreportingColorFabricOrderQty,
  reportColorFabricOrderQty,
  sendToPurchaseSupplier,
  updatePurchaseFabricOrder,
  exportFabricOrder,
} from '@/api/fabric'
import { exportNotification, getRecentMonths } from '@/utils/util'
import { Button, Empty, message, Modal, Space, Spin, Typography } from 'antd'
import useModal from '@/hooks/useModal'
import { EditFormVertical } from '@/components/QsfCustomForm'
import useGetProDevSeason from '@/hooks/useGetProDevSeason'
import { applicationTypeEnum, OperationLogType } from '@/constant'
import useViewLogs from '@/hooks/useViewLogs'
import LogsDrawer from '@/components/LogsDrawer'
import useSearchSupplier from '@/hooks/useSearchSupplier'
import dayjs from 'dayjs'
import { getSupplierByFabricCode } from '@/api/purchase'
import PermissionButton from '@/components/PermissionButton'
import { UploadOutlined } from '@ant-design/icons'
import { useNavigate } from 'react-router-dom'
import { ExclamationCircleOutlined } from '@ant-design/icons'
export interface IMenuItem {
  label: string | React.ReactNode
  key: string
}
const Index: React.FC = () => {
  let SpuTimeout: ITimeoutType
  let FTimeout: ITimeoutType
  const navigate = useNavigate()
  const [form] = useForm()
  const ProDevSeason = useGetProDevSeason()
  const [operateItems, setoperateItems] = useState<IMenuItem[]>([])
  const [SpuOptions, setSpuOptions] = useState<IOptionItem[]>([])
  const [SpecLoading, setSpecLoading] = useState(false)
  const [exportLoading, setexportLoading] = useState(false)
  const [spinning, setspinning] = useState(false)
  const [selectedRowKeys, setselectedRowKeys] = useState<React.Key[]>([])
  const [selectedRows, setselectedRows] = useState<ITableData[]>([])
  const [classBig, setclassBig] = useState<IOptionItem[]>([])
  const [orderNum, setorderNum] = useState(0)
  const applicationId = useAppSelector((state) => state.user.user_info.applicationId)
  const isRoot = applicationId == applicationTypeEnum.SOP_SEVENFUN_WEB
  const {
    SupplierOption: SupplierOptionF,
    handleSearchSupplier: handleSearchSupplierF,
    setSupplierOption: setSupplierOptionF,
  } = useSearchSupplier('supplierCode')
  const {
    SupplierOption: SupplierOptionC,
    handleSearchSupplier: handleSearchSupplierC,
    setSupplierOption: setSupplierOptionC,
  } = useSearchSupplier('supplierCode')
  const { isLogShow, setisLogShow, logLoading, logInfos, setLogInfos, viewLogs } = useViewLogs(
    'id',
    OperationLogType.PURCHASE_FABRIC_ORDER,
  )
  const reqSecondParams = useRef<Record<string, any>>({})
  const reportModal = useModal({
    autoClose: false,
    onSuccess: () => {
      message.success('操作成功')
      reload()
    },
    onFail: (error) => {
      if (error?.code === 820000 && reportModal.currentRecord?.type == 2) {
        const instance = Modal.confirm({
          title: '提示',
          content: error?.msg,
          okText: '确认',
          cancelText: '取消',
          icon: <ExclamationCircleOutlined />,
          onOk: async () => {
            const res = await reportColorFabricOrderQty({
              ...reqSecondParams.current,
              skipReportEmbryoFabric: 1,
            }).finally(() => {
              instance.destroy()
              reportModal.closeModal()
            })
            if (res.code === 200) {
              reload()
              message.success('操作成功')
            }
          },
        })
      }
    },
  })
  const editModal = useModal({
    onSuccess: () => {
      message.success('操作成功')
      reload()
    },
  })
  const { setCachePage, getCachePage } = useCachePage()
  const defaultDateRange = getRecentMonths('YYYY-MM-DD HH:mm:ss')
  const buttonCodeList = useAppSelector((state) => state.login.buttonCodeList) || []
  const [FabricSupplierOptions, setFabricSupplierOptions] = useState<IOptionItem[]>([])
  const { tableProps, params, search, reset, reload } = useGetTableData<ITableData>(getFabricOrderPage, {
    form: form,
    immediatelySend: false,
    defaultFieldsParams: {
      createTimeStart: defaultDateRange,
    },
    cachePageCallback: (current, size, prevSize) => {
      const cacheData = getCachePage()
      setCachePage({
        ...cacheData,
        current: prevSize === size ? current : 1,
        size,
      })
    },
    paramsCallback: (reqestParams) => {
      const { pageRange, mainProductTag, expand, ...reqParams } = reqestParams
      return {
        ...reqParams,
        createTimeStart:
          reqParams.createTimeStart && reqParams.createTimeStart.length === 2 ? reqParams.createTimeStart[0] : null,
        createTimeEnd:
          reqParams.createTimeStart && reqParams.createTimeStart.length === 2 ? reqParams.createTimeStart[1] : null,
      }
    },
  })
  const getToDoList = async () => {
    const res = await getUnReplyDateCount({ replyDateStatus: 0 })
    if (res.code === 200) {
      setorderNum(res?.data || 0)
    }
  }
  useEffect(() => {
    handleCacheData()
    handleOperateItems()
    getProductClassConfig()
    getToDoList()
  }, [])
  const getProductClassConfig = async (type: 1 | 2 | 3 | 4 = 1) => {
    const res = await getProductClassConfigByType<{
      className: string
      classConfigId: string | number
    }>({ type, auth: 1 })
    const classIdOptions =
      res?.data?.map((item) => {
        return {
          label: item.className,
          value: item.classConfigId,
        }
      }) || []
    setclassBig(classIdOptions)
  }
  const handleOperateItems = () => {
    const items = [] as IMenuItem[]
    const defPer = [
      { label: '回复交期', key: 'FactoryOrderReplyDate' },
      // { label: '汇报成品色布', key: 'FactoryOrderReplyFabricCode' },
      // { label: '发货', key: 'FactoryOrderSendGoods' },
      {
        label: <span style={{ color: 'red', fontWeight: 800 }}>成品误汇报-色布</span>,
        key: 'FactoryOrderMisReporting',
      },
      { label: <span style={{ color: 'red', fontWeight: 800 }}>面料错发货</span>, key: 'FactoryOrderSendWrong' },
    ]
    defPer.forEach((item) => {
      if (buttonCodeList.includes(item.key)) {
        items.push(item)
      }
    })
    setoperateItems(items)
  }
  const handleMenuClick = (info: ITableData, items: any) => {
    if (items.key === 'FactoryOrderReplyDate') {
      onReply(info, 1)
    } else if (items.key === 'FactoryOrderReplyFabricCode') {
      onReply(info, 2)
    } else if (items.key === 'FactoryOrderSendGoods') {
      onReply(info, 3)
    } else if (items.key === 'FactoryOrderMisReporting') {
      onReply(info, 4)
    } else if (items.key === 'FactoryOrderSendWrong') {
      onReply(info, 5)
    }
  }
  const handleCacheData = async () => {
    const cacheData = getCachePage()
    if (cacheData == null) {
      await form.validateFields()
      search()
      setCachePage({ ...params })
    } else {
      const { SupplierOptionF, SupplierOptionC, SpuOptions, ...resetCacheData } = cacheData
      // 先重置表单再设置缓存！！！
      form.resetFields()
      form.setFieldsValue({
        ...resetCacheData,
      })
      setSpuOptions(SpuOptions || [])
      setSupplierOptionF(SupplierOptionF || [])
      setSupplierOptionC(SupplierOptionC || [])
      reload({ ...resetCacheData })
    }
  }
  const onViewLogs = (info: ITableData) => {
    viewLogs(info)
  }
  const onReply = (info: ITableData, type: 1 | 2 | 3 | 4 | 5) => {
    const { colorFabricFinishQty, produceRemark, thisDeliveryQty, flowRemark, ...setinfo } = info
    reportModal.openModal({ ...setinfo, type })
  }
  const onEdit = (info: ITableData, type: 1 | 2 | 3 | 4 | 5) => {
    if (type == 5) {
      handleSearchSupplierByCode(info?.fabricCode || '')
    }
    const { supplierCode, ...set } = info
    editModal.openModal({ ...set, type })
  }
  const handleSearchSpuOptions = (newValue = '') => {
    if (!newValue) return
    if (SpuTimeout) {
      clearTimeout(SpuTimeout)
      SpuTimeout = null
    }
    const getOptions = async () => {
      const res = await getSpuOptions<{
        spuName: string
        spuId: string
        spuCode: string
        designCode: string
      }>({ keyword: newValue })
      if (res.code === 200) {
        const data =
          res?.data?.map((item) => {
            return {
              label: `${item?.spuCode}｜${item.spuName}${item?.designCode ? '｜' + item?.designCode : ''}`,
              value: item.spuCode,
            }
          }) || []
        setSpuOptions(data)
      }
    }
    SpuTimeout = setTimeout(getOptions, 500)
  }
  const handleSearchSupplierByCode = (fabricCode: string) => {
    if (!fabricCode) return
    if (FTimeout) {
      clearTimeout(FTimeout)
      FTimeout = null
    }
    const getOptions = async () => {
      const res = await getSupplierByFabricCode<{
        supplierCode: string
        supplierName: string
      }>({ fabricCode })
      if (res.code === 200) {
        const data =
          res?.data?.map((item) => {
            return {
              label: item.supplierName,
              value: item.supplierCode,
            }
          }) || []
        setFabricSupplierOptions(data)
      }
    }
    FTimeout = setTimeout(getOptions, 500)
  }
  return (
    <PageContainer className="fabric_fatoryorder_wrap">
      <div className="waittodo_box">
        <div className="wait_main">
          <div className="wm_item">
            <div className="wm_item_title">待回复交期</div>
            <div className="wm_item_num">
              <Typography.Link
                underline
                onClick={() => {
                  form.resetFields()
                  form.setFieldsValue({
                    replyDateStatus: 0,
                  })
                  search()
                  setCachePage({
                    ...form.getFieldsValue(),
                    current: 1,
                    size: params.size,
                  })
                  setselectedRowKeys([])
                  setselectedRows([])
                }}
              >
                {orderNum}单
              </Typography.Link>
            </div>
          </div>
          <div className="wm_item"></div>
        </div>
      </div>
      <SearchForm
        loading={tableProps.loading}
        form={form}
        searchConfig={searchConfig({
          SpuOptions,
          handleSearchSpuOptions,
          SupplierOptionF,
          SupplierOptionC,
          handleSearchSupplierF,
          handleSearchSupplierC,
          ProDevSeason,
          classBig,
          form,
        })}
        onFinish={async () => {
          setCachePage({
            ...form.getFieldsValue(),
            SupplierOptionF,
            SupplierOptionC,
            SpuOptions,
            handleSearchSupplierF,
            handleSearchSupplierC,
            current: 1,
            size: params.size,
          })
          search()
          setselectedRowKeys([])
          setselectedRows([])
        }}
        onReset={() => {
          reset()
          setCachePage({
            current: 1,
            size: 10,
            createTimeStart: defaultDateRange,
          })
          setselectedRowKeys([])
          setselectedRows([])
        }}
        extra={
          <div className="table_extra_flex_wrapbox">
            <div className="table_extra_flex">
              <PermissionButton
                permission="FactoryOrderReplyDate"
                type="primary"
                onClick={() => {
                  if (selectedRowKeys.length === 0) {
                    message.warning('请勾选需要操作的列表数据！')
                    return
                  }
                  reportModal.openModal({ type: 6 })
                }}
                disabled={tableProps.loading}
              >
                批量回复交期
              </PermissionButton>
            </div>
            <div className="table_extra_flex">
              <PermissionButton
                permission="FactoryOrderExport"
                onClick={async () => {
                  const paramsData: Record<string, any> = {}
                  if (selectedRowKeys.length > 0) {
                    paramsData.purchaseOrderFabricIds = selectedRowKeys
                  } else {
                    Object.assign(paramsData, params)
                  }
                  setexportLoading(true)
                  setspinning(true)
                  const res = await exportFabricOrder(paramsData)
                    .catch(() => setspinning(false))
                    .finally(() => {
                      setexportLoading(false)
                      setselectedRowKeys([])
                      setselectedRows([])
                    })
                  if (res?.code === 200 && res?.data) {
                    await exportNotification(res?.data, navigate).finally(() => setspinning(false))
                  }
                }}
                icon={<UploadOutlined />}
                loading={exportLoading}
              >
                导出
              </PermissionButton>
            </div>
          </div>
        }
      ></SearchForm>
      <CustomTable
        stripe={false}
        isAutoScrollY
        extraHeight={86}
        {...tableProps}
        columns={useIndexColumns({
          isRoot,
          onEdit,
          operateItems,
          handleMenuClick,
          onViewLogs,
          FactoryOrderEditUnitUsedNum: buttonCodeList.includes('FactoryOrderEditUnitUsedNum'),
          FactoryOrderEditOrderQty: buttonCodeList.includes('FactoryOrderEditOrderQty'),
          FactoryOrderEditIntentDate: buttonCodeList.includes('FactoryOrderEditIntentDate'),
          FactoryOrderEditOrderRemark: buttonCodeList.includes('FactoryOrderEditOrderRemark'),
          FactoryOrderEditFabricSupplier: buttonCodeList.includes('FactoryOrderEditFabricSupplier'),
        })}
        rowKey={(rows) => rows?.id}
        rowSelection={{
          selectedRowKeys,
          onChange(selectedRowKeys, selectedRows) {
            setselectedRowKeys(selectedRowKeys)
            setselectedRows(selectedRows)
          },
        }}
      ></CustomTable>
      <LogsDrawer {...{ isLogShow, setisLogShow, logLoading, logInfos, setLogInfos }}></LogsDrawer>
      <Modal
        title={
          reportModal.currentRecord?.type == 1 || reportModal.currentRecord?.type == 6
            ? '回复交期'
            : reportModal.currentRecord?.type == 2
            ? '汇报成品色布'
            : reportModal.currentRecord?.type == 3
            ? '发货'
            : reportModal.currentRecord?.type == 4
            ? '成品误汇报-色布'
            : reportModal.currentRecord?.type == 5
            ? '面料错发货'
            : null
        }
        open={reportModal.open}
        maskClosable
        onCancel={reportModal.closeModal}
        footer={
          <div className="flex_end">
            <Space>
              <Button onClick={reportModal.closeModal}>取消</Button>
              {reportModal.currentRecord?.type == 2 && (
                <Button
                  loading={reportModal.confirmLoading || SpecLoading}
                  style={{ background: 'var(--warning-color)', color: '#fff' }}
                  onClick={async () => {
                    try {
                      const vals = await reportModal.form.validateFields()
                      setSpecLoading(true)
                      const paramsData = {
                        ...vals,
                        id: reportModal.currentRecord?.id || null,
                        purchaseOrderCode: reportModal.currentRecord?.purchaseOrderCode || null,
                        supplierCode: reportModal.currentRecord?.supplierCode || null,
                        colorFabricCode: reportModal.currentRecord?.colorFabricCode || null,
                        useSite: reportModal.currentRecord?.useSite || null,
                        skipReportEmbryoFabric: 0,
                      }
                      const res = await reportColorFabricOrderQty(paramsData)
                        .catch(() => {
                          reload()
                        })
                        .finally(() => {
                          setSpecLoading(false)
                        })
                      if (res?.code === 820000) {
                        const instance = Modal.confirm({
                          title: '提示',
                          content: res?.msg,
                          okText: '确认',
                          cancelText: '取消',
                          icon: <ExclamationCircleOutlined />,
                          onOk: async () => {
                            const res = await reportColorFabricOrderQty({
                              ...paramsData,
                              skipReportEmbryoFabric: 1,
                            }).finally(() => {
                              instance.destroy()
                              reportModal.closeModal()
                            })
                            if (res.code === 200) {
                              const result = await sendToPurchaseSupplier({
                                id: reportModal.currentRecord?.id || null,
                                thisDeliveryQty: vals?.colorFabricFinishQty,
                                purchaseOrderCode: reportModal.currentRecord?.purchaseOrderCode || null,
                                supplierCode: reportModal.currentRecord?.supplierCode || null,
                                colorFabricCode: reportModal.currentRecord?.colorFabricCode || null,
                                useSite: reportModal.currentRecord?.useSite || null,
                              }).finally(() => {
                                reload()
                              })
                              if (result.code == 200) {
                                message.success('操作成功')
                              }
                            }
                          },
                        })
                      }
                      if (res?.code == 200) {
                        const result = await sendToPurchaseSupplier({
                          id: reportModal.currentRecord?.id || null,
                          thisDeliveryQty: vals?.colorFabricFinishQty,
                          purchaseOrderCode: reportModal.currentRecord?.purchaseOrderCode || null,
                          supplierCode: reportModal.currentRecord?.supplierCode || null,
                          colorFabricCode: reportModal.currentRecord?.colorFabricCode || null,
                          useSite: reportModal.currentRecord?.useSite || null,
                        }).finally(() => {
                          reload()
                          reportModal.closeModal()
                        })
                        if (result?.code == 200) {
                          message.success('操作成功')
                        }
                      }
                      if (res == undefined) return
                    } catch (error) {
                      console.log(error)
                    }
                  }}
                >
                  汇报并直接发货
                </Button>
              )}
              <Button
                type="primary"
                loading={reportModal.confirmLoading || SpecLoading}
                onClick={() => {
                  if (reportModal.currentRecord?.type == 1) {
                    reportModal.handleSubmit((vals) =>
                      batchUpdateReplyDate({
                        ...vals,
                        ids: reportModal.currentRecord?.id ? [reportModal.currentRecord?.id] : null,
                      }).finally(() => getToDoList()),
                    )
                  } else if (reportModal.currentRecord?.type == 2) {
                    reportModal.handleSubmit((vals) => {
                      const params = {
                        ...vals,
                        id: reportModal.currentRecord?.id || null,
                        purchaseOrderCode: reportModal.currentRecord?.purchaseOrderCode || null,
                        supplierCode: reportModal.currentRecord?.supplierCode || null,
                        colorFabricCode: reportModal.currentRecord?.colorFabricCode || null,
                        useSite: reportModal.currentRecord?.useSite || null,
                        skipReportEmbryoFabric: 0,
                      }
                      reqSecondParams.current = params
                      return reportColorFabricOrderQty(params)
                        .catch(() => {
                          reload()
                        })
                        .finally(() => {
                          setSpecLoading(false)
                          // reportModal.closeModal()
                        })
                    })
                  } else if (reportModal.currentRecord?.type == 3) {
                    reportModal.handleSubmit((vals) =>
                      sendToPurchaseSupplier({
                        ...vals,
                        id: reportModal.currentRecord?.id || null,
                        purchaseOrderCode: reportModal.currentRecord?.purchaseOrderCode || null,
                        supplierCode: reportModal.currentRecord?.supplierCode || null,
                        colorFabricCode: reportModal.currentRecord?.colorFabricCode || null,
                        useSite: reportModal.currentRecord?.useSite || null,
                      }),
                    )
                  } else if (reportModal.currentRecord?.type == 4) {
                    reportModal.handleSubmit((vals) =>
                      misreportingColorFabricOrderQty({
                        ...vals,
                        id: reportModal.currentRecord?.id || null,
                        purchaseOrderCode: reportModal.currentRecord?.purchaseOrderCode || null,
                        supplierCode: reportModal.currentRecord?.supplierCode || null,
                        colorFabricCode: reportModal.currentRecord?.colorFabricCode || null,
                        useSite: reportModal.currentRecord?.useSite || null,
                      }),
                    )
                  } else if (reportModal.currentRecord?.type == 5) {
                    reportModal.handleSubmit((vals) =>
                      misDeliveryToPurchaseSupplier({
                        ...vals,
                        id: reportModal.currentRecord?.id || null,
                        purchaseOrderCode: reportModal.currentRecord?.purchaseOrderCode || null,
                        supplierCode: reportModal.currentRecord?.supplierCode || null,
                        colorFabricCode: reportModal.currentRecord?.colorFabricCode || null,
                        useSite: reportModal.currentRecord?.useSite || null,
                      }),
                    )
                  } else if (reportModal.currentRecord?.type == 6) {
                    setselectedRowKeys([])
                    setselectedRows([])
                    reportModal.handleSubmit((vals) =>
                      batchUpdateReplyDate({
                        ...vals,
                        ids: selectedRowKeys,
                      }).finally(() => getToDoList()),
                    )
                  }
                }}
              >
                确定
              </Button>
            </Space>
          </div>
        }
      >
        <EditFormVertical
          editConfig={[
            {
              name: 'replyDate',
              label: '回复交期',
              type: 'FixedDatePicker',
              placeholder: '请选择回复交期',
              config: {
                customFormat: 'YYYY-MM-DD',
                minDate: dayjs(),
              },
              rules: [
                {
                  required: true,
                  message: '请选择回复交期',
                },
              ],
              hidden: !(reportModal.currentRecord?.type == 1 || reportModal.currentRecord?.type == 6),
            },
            {
              name: 'colorFabricFinishQty',
              label: '色布成品量',
              type: 'InputNumber',
              placeholder: '请输入色布成品量',
              config: {
                precision: 2,
                min: 0,
              },
              rules: [
                {
                  required: true,
                  message: '请输入色布成品量',
                },
              ],
              hidden: reportModal.currentRecord?.type != 2,
            },
            {
              name: 'produceRemark',
              label: '生产备注',
              type: 'TextArea',
              placeholder: '请输入生产备注',
              config: {
                rows: 3,
              },
              rules: [
                {
                  required: false,
                  message: '请输入生产备注',
                },
              ],
              hidden: reportModal.currentRecord?.type != 2,
            },
            {
              name: 'thisDeliveryQty',
              label: '本次发货量',
              type: 'InputNumber',
              placeholder: '请输入本次发货量',
              config: {
                precision: 2,
                min: 0,
              },
              rules: [
                {
                  required: true,
                  message: '请输入本次发货量',
                },
              ],
              hidden: reportModal.currentRecord?.type != 3,
            },
            {
              name: 'colorFabricFinishQty',
              label: '误汇报数量',
              type: 'InputNumber',
              placeholder: '请输入误汇报数量',
              config: {
                precision: 2,
                min: 0,
              },
              rules: [
                {
                  required: true,
                  message: '请输入误汇报数量',
                },
              ],
              hidden: reportModal.currentRecord?.type != 4,
            },
            {
              name: 'thisDeliveryQty',
              label: '错发货数量',
              type: 'InputNumber',
              placeholder: '请输入错发货数量',
              config: {
                precision: 2,
                min: 0,
              },
              rules: [
                {
                  required: true,
                  message: '请输入错发货数量',
                },
              ],
              hidden: reportModal.currentRecord?.type != 5,
            },
            {
              name: 'flowRemark',
              label: '流水备注',
              type: 'TextArea',
              placeholder: '请输入流水备注',
              config: {
                rows: 3,
              },
              rules: [
                {
                  required: true,
                  message: '请输入流水备注',
                },
              ],
              hidden: !(reportModal.currentRecord?.type == 4 || reportModal.currentRecord?.type == 5),
            },
          ]}
          form={reportModal.form}
        />
      </Modal>
      <Modal
        title={
          editModal.currentRecord?.type == 1
            ? '单件用量'
            : editModal.currentRecord?.type == 2
            ? '色布实际下单量'
            : editModal.currentRecord?.type == 3
            ? '制衣厂意向交期'
            : editModal.currentRecord?.type == 4
            ? '订单备注'
            : editModal.currentRecord?.type == 5
            ? '面料供应商'
            : null
        }
        open={editModal.open}
        maskClosable
        onCancel={() => {
          if (editModal.currentRecord?.type == 5) {
            setFabricSupplierOptions([])
          }
          editModal.closeModal()
        }}
        footer={
          <div className="flex_end">
            <Space>
              <Button
                onClick={() => {
                  if (editModal.currentRecord?.type == 5) {
                    setFabricSupplierOptions([])
                  }
                  editModal.closeModal()
                }}
              >
                取消
              </Button>
              <Button
                type="primary"
                loading={editModal.confirmLoading}
                onClick={() => {
                  if (editModal.currentRecord?.type == 5) {
                    setFabricSupplierOptions([])
                  }
                  editModal.handleSubmit((vals) =>
                    updatePurchaseFabricOrder({
                      ...vals,
                      id: editModal.currentRecord?.id || null,
                    }),
                  )
                }}
              >
                确定
              </Button>
            </Space>
          </div>
        }
      >
        <EditFormVertical
          editConfig={[
            {
              name: 'unitUsedNum',
              label: '单件用量',
              type: 'InputNumber',
              placeholder: '请输入单件用量',
              config: {
                precision: 6,
                min: 0,
              },
              rules: [
                {
                  required: true,
                  message: '请输入单件用量',
                },
              ],
              hidden: editModal.currentRecord?.type != 1,
            },
            {
              name: 'colorFabricOrderQty',
              label: '色布实际下单量',
              type: 'InputNumber',
              placeholder: '请输入色布实际下单量',
              config: {
                precision: 2,
                min: 0,
              },
              rules: [
                {
                  required: true,
                  message: '请输入色布实际下单量',
                },
              ],
              hidden: editModal.currentRecord?.type != 2,
            },
            {
              name: 'intentDate',
              label: '制衣厂意向交期',
              type: 'FixedDatePicker',
              placeholder: '请选择制衣厂意向交期',
              config: {
                customFormat: 'YYYY-MM-DD',
                minDate: dayjs(),
              },
              rules: [
                {
                  required: true,
                  message: '请选择制衣厂意向交期',
                },
              ],
              hidden: editModal.currentRecord?.type != 3,
            },
            {
              name: 'orderRemark',
              label: '订单备注',
              type: 'TextArea',
              placeholder: '请输入订单备注',
              config: {
                rows: 3,
              },
              rules: [
                {
                  required: true,
                  message: '请输入订单备注',
                },
              ],
              hidden: editModal.currentRecord?.type != 4,
            },
            {
              name: 'supplierCode',
              label: '面料供应商',
              type: 'Select',
              placeholder: '请选择面料供应商',
              option: FabricSupplierOptions,
              config: {
                suffixIcon: null,
                showSearch: true,
                optionFilterProp: 'label',
                notFoundContent: <Empty description="请输入内容搜索" image={Empty.PRESENTED_IMAGE_SIMPLE} />,
              },
              rules: [
                {
                  required: true,
                  message: '请选择面料供应商',
                },
              ],
              hidden: editModal.currentRecord?.type != 5,
            },
          ]}
          form={editModal.form}
        />
      </Modal>
      <Spin spinning={spinning} fullscreen />
    </PageContainer>
  )
}

export default Index
